﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;

namespace PYS.DataAccess
{
    public class DataAccess
    {
        public static string UserIsValid(string email, string cnp)
        {
            string userName = null;
            PYSEntities context = new PYSEntities();
            decimal cnpDecimal = Decimal.Parse(cnp);
            user user = context.users.FirstOrDefault(u => u.CNP == cnpDecimal && u.email == email);
            if (user != null)
            {
                userName = user.CNP.ToString();
            }
            return userName;
        }


        public static string InsertUser(string lname, string fname, string email, string cnp)
        {
            PYSEntities context = new PYSEntities();
            string message = "success";
            decimal cnpDecimal = Decimal.Parse(cnp);
            user user = context.users.FirstOrDefault(u => u.CNP == cnpDecimal);
            if (user != null)
                message = "DuplicateUserName";
            else
            {
                context.users.AddObject(new user { lastName = lname, firstName = fname, email = email, CNP = Decimal.Parse(cnp) });
                context.SaveChanges();
            }
            return message;
        }
    }
}